package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.course.dto.bo.CommonRespBO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CourseAll;
import com.ruoyi.course.service.ICourseAllService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程信息Controller
 *
 * @author mac
 * @date 2023-03-11
 */
@RestController @RequestMapping("/course/courseAll") public class CourseAllController extends BaseController {
    @Autowired private ICourseAllService courseAllService;

    /**
     * 查询课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAll:list')") @GetMapping("/list") public TableDataInfo list(
        CourseAll courseAll) {
        startPage();
        List<CourseAll> list = courseAllService.selectCourseAllList(courseAll);
        return getDataTable(list);
    }

    @GetMapping("/listAllTeacher") public AjaxResult listAllTeacher() {
        return AjaxResult.success(courseAllService.selectAllTeacherList());
    }

    @GetMapping("/listAllCourse") public AjaxResult listAllCourse() {
        return AjaxResult.success(courseAllService.selectAllCourseList());
    }

    @GetMapping("/listAllCoursePart") public AjaxResult listAllCoursePart() {
        return AjaxResult.success(courseAllService.selectAllCoursePartList());
    }

    /**
     * 导出课程信息列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAll:export')") @Log(title = "课程信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export") public void export(HttpServletResponse response, CourseAll courseAll) {
        List<CourseAll> list = courseAllService.selectCourseAllList(courseAll);
        ExcelUtil<CourseAll> util = new ExcelUtil<CourseAll>(CourseAll.class);
        util.exportExcel(response, list, "课程信息数据");
    }

    /**
     * 获取课程信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseAll:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(
        @PathVariable("id") Long id) {
        return AjaxResult.success(courseAllService.selectCourseAllById(id));
    }

    /**
     * 新增课程信息
     */
    @Log(title = "课程信息", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(
        @RequestBody CourseAll courseAll) {
        return toAjax(courseAllService.insertCourseAll(courseAll));
    }

    /**
     * 修改课程信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseAll:edit')") @Log(title = "课程信息", businessType = BusinessType.UPDATE)
    @PutMapping public AjaxResult edit(@RequestBody CourseAll courseAll) {
        return toAjax(courseAllService.updateCourseAll(courseAll));
    }

    /**
     * 删除课程信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseAll:remove')") @Log(title = "课程信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(courseAllService.deleteCourseAllByIds(ids));
    }
}
